package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.entity.VerCouponGroup;
import com.ruoyi.service.VerCouponGroupsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/group")
public class VerCouponGroupController extends BaseController {
    @Autowired
    private VerCouponGroupsService verCouponGroupsService;

    /**
     * 查询优惠券组列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(VerCouponGroup verCouponGroup)
    {
        startPage();
        List<VerCouponGroup> list = verCouponGroupsService.selectAll(verCouponGroup);
        return getDataTable(list);
    }


    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(verCouponGroupsService.selectById(id));
    }

    /**
     * 新增优惠券组
     */
//    @PreAuthorize("@ss.hasPermi('system:group:add')")
    @Log(title = "【新增优惠券组】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody VerCouponGroup verCouponGroup)
    {
        return toAjax(verCouponGroupsService.insert(verCouponGroup));
    }

    /**
     * 修改优惠券组
     */
//    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "【修改优惠券组】", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody VerCouponGroup verCouponGroup)
    {
        return toAjax(verCouponGroupsService.update(verCouponGroup));
    }

    /**
     * 删除优惠券组
     */
//    @PreAuthorize("@ss.hasPermi('system:group:remove')")
    @Log(title = "【删除优惠券组】", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(verCouponGroupsService.deleteById(ids));
    }
}
